package com.study.favorite.mapper;

import com.study.favorite.pojo.Favorite;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface FavoriteMapper {

     // 增
    @Insert("insert into favorite values (default, #{flable}, #{furl}, #{fdesc}, #{ftags})")
    @Options(useGeneratedKeys = true,keyColumn = "fid", keyProperty = "fid")
    int insert(Favorite favorite);

    // 改
    @Update("update favorite set " + " flable=#{flable},furl=#{furl},fdesc=#{fdesc},ftags=#{ftags}" + " where fid=#{fid}")
    int update(Favorite favorite);

    // 查
    @Select("select * from favorite")
    List<Favorite> selectALL();

    @Select("select * from favorite where ftags is null")
    List<Favorite> selectNoFtags();

    @Select("select * from favorite a" +
            " join tagfavorite b on a.fid=b.fid" +
            " where b.tid=#{tid}")
    List<Favorite> selectByTid(int tid);
}
